package com.shpng.cheapenglish.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shpng.cheapenglish.entity.SUser;
import com.shpng.cheapenglish.entity.SUserUnit;
import com.shpng.cheapenglish.manager.UserManager;
import com.shpng.cheapenglish.manager.WordManager;

public class ChooseUnitAction {

	public String execute(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		WordManager wordManager = WordManager.getInstance();
		UserManager userManager = UserManager.getInstance();
		String email = (String) req.getSession().getAttribute("email");
		SUser user = userManager.getUser(email);
		List<SUserUnit> userUnits = wordManager.getUserUnits(user);
		StringBuilder sb = new StringBuilder();
		for (SUserUnit suu : userUnits) {
			sb.append(suu.getUnit());
			sb.append(",");
		}

		resp.getWriter().print(
				sb.length() > 0 ? sb.substring(0, sb.length() - 1) : "");

		return null;
	}
}
